package com.clstu.encap01;

public class Account {
    private String name;
    private double balance;
    private String pwd;

    public Account() {
    }

    public Account(String name, double balance, String pwd) {
        setName(name);
        setBalance(balance);
        setPwd(pwd);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if(name.length()>=2&&name.length()<=6)
        this.name = name;
        else{
            System.out.println("你输入的姓名长度不合法，（2-6）位，默认：王富贵");
            this.name="王富贵";
        }
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        if(balance>=20)
        this.balance = balance;
        else{
            System.out.println("你的余额太少了，（》20），默认为0");
            this.balance=0;
        }
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        if(pwd.length()==6)
        this.pwd = pwd;
        else{
            System.out.println("你设置的密码长度不合法，（6）位，默认为：000000");
            this.pwd="000000";
        }
    }

    public String info(){
        return "账号信息：\n用户名： "+name+"\n密码： "+pwd+ "\n余额： "+balance;
    }

    public void showInfo(){
        System.out.println("账号信息：\n用户名： "+name+"\n密码： "+pwd+ "\n余额： "+balance);
    }
}
